/**
 * Copyright (C) 2008 GeoScheduler Team, as stated on <http://www.geoscheduler.org/authors>.
 * 
 * This file is part of GeoScheduler.
 * 
 * GeoScheduler is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GeoScheduler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with GeoScheduler. If not, see <http://www.gnu.org/licenses/>.
 */

package org.geoscheduler.commons.marshaller;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 
 * <h2>JSONMarshaller</h2>
 * 
 * <p>
 * JSONMarsahller implementation control marshalling and unmarshalling process
 * of objects. Marshalling/Unmarshalling of particular values is done using
 * {@link JSONFieldDecl} implementations.
 * </p>
 * 
 * @see JSONFieldDecl
 * @author LKo (Lukas.Kolisko@Geoscheduler.Org)
 */
public interface JSONMarshaller {

	/**
	 * Unmarshall json object obj into specified instance.
	 * 
	 * @param instance -
	 *            target instance for unmarshalling
	 * @param obj -
	 *            json data source for unmarshalling
	 * @return instance setup with unmarshalled data
	 * @throws JSONException -
	 *             if unmarshalling process fails
	 */
	<T> T unmarshall(T instance, JSONObject obj) throws JSONException;

	/**
	 * Marshall <code>instance</code> fields annotated with {@link JSONField}
	 * annotation to provided {@link JSONObject} instance <code>obj</code>.
	 * 
	 * @param instance -
	 *            data source for marshalling
	 * @param obj -
	 *            target for marshalling
	 * @return <code>obj</code> instance setup with marshalled data.
	 * @throws JSONException
	 */
	JSONObject marshall(Object instance, JSONObject obj) throws JSONException;
}
